package com.woniuxy.creditsystem.dashboardmag.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.common.bean.*;
import com.woniuxy.creditsystem.dashboardmag.service.IDashboardInfo;
import com.woniuxy.creditsystem.financialmag.service.IPutMoneyInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @author ：pengchufeng
 * @date ：Created in 2020/12/16
 * @description：仪表盘信息controller
 */
@RequestMapping("/dbinfo")
@RestController
public class DashboardController {

    @Resource
    private IDashboardInfo dashboardInfoImpl;

    /**
     * 无条件查询所有仪表盘信息
     * @return
     */
    @RequestMapping(value="/selectAll",produces = {"application/json;charset=utf-8"})
    public List<DashboardInfo> findAll(DashboardInfo dashboardInfo){
        List<DashboardInfo> lp = dashboardInfoImpl.findAll(dashboardInfo);
        for(int i = 0;i < lp.size();i++){
            DashboardInfo p1 = lp.get(i);
        }
        return lp;
    }

    /**
     * 无条件查询所有仪表盘信息
     * @return
     */
    @RequestMapping(value="/selectFirst",produces = {"application/json;charset=utf-8"})
    public List<DashboardInfo> findFirst(DashboardInfo dashboardInfo){
        String channel = dashboardInfo.getChannel();
        List<DashboardInfo> lp = dashboardInfoImpl.findFirst(dashboardInfo);
        for(int i = 0;i < lp.size();i++){
            DashboardInfo p1 = lp.get(i);
            if(channel == null || channel == ""){
                p1.setStrSPM(new DecimalFormat("0.00").format(p1.getSumPutMoney()));
                p1.setStrSRM(new DecimalFormat("0.00").format(p1.getSumReturnMoney()));
                p1.setStrSAM(new DecimalFormat("0.00").format(p1.getSumReturnMoney().multiply(new BigDecimal("0.8"))));
                p1.setStrSYM(new DecimalFormat("0.00").format(p1.getSumReturnMoney().multiply(new BigDecimal("0.4"))));
            }else if(channel.equals("1")){
                p1.setStrSPM(new DecimalFormat("0.00").format(p1.getSumPutMoney().multiply(new BigDecimal("0.6"))));
                p1.setStrSRM(new DecimalFormat("0.00").format(p1.getSumReturnMoney().multiply(new BigDecimal("0.6"))));
                p1.setStrSAM(new DecimalFormat("0.00").format(p1.getSumReturnMoney().multiply(new BigDecimal("0.8")).multiply(new BigDecimal("0.6"))));
                p1.setStrSYM(new DecimalFormat("0.00").format(p1.getSumReturnMoney().multiply(new BigDecimal("0.4")).multiply(new BigDecimal("0.6"))));
            }else{
                p1.setStrSPM(new DecimalFormat("0.00").format(p1.getSumPutMoney().multiply(new BigDecimal("0.4"))));
                p1.setStrSRM(new DecimalFormat("0.00").format(p1.getSumReturnMoney().multiply(new BigDecimal("0.4"))));
                p1.setStrSAM(new DecimalFormat("0.00").format(p1.getSumReturnMoney().multiply(new BigDecimal("0.8")).multiply(new BigDecimal("0.4"))));
                p1.setStrSYM(new DecimalFormat("0.00").format(p1.getSumReturnMoney().multiply(new BigDecimal("0.4")).multiply(new BigDecimal("0.4"))));
            }
        }
        return lp;
    }

    /**
     * 无条件查询所有仪表盘信息
     * @return
     */
    @RequestMapping(value="/selectCount",produces = {"application/json;charset=utf-8"})
    public List<ReturnMoneyCount> findCount(ReturnMoneyCount returnMoneyCount){
        if(returnMoneyCount.getStrDate() != null && returnMoneyCount.getStrDate() != "" ){
            returnMoneyCount.setStrDateA(null);
            returnMoneyCount.setStrDateB(null);
        }
        List<ReturnMoneyCount> lp = dashboardInfoImpl.findCount(returnMoneyCount);
        for(int i = 0;i < lp.size();i++) {
            ReturnMoneyCount p1 = lp.get(i);
            if(p1.getDateSRM() != null){
                p1.setStrD(new DecimalFormat("0.00").format(p1.getDateSRM()));
            }else{
                p1.setStrD("0.00");
            }
            if(p1.getTodaySRM() != null) {
                p1.setStrT(new DecimalFormat("0.00").format(p1.getTodaySRM()));
            } else {
                p1.setStrT("0.00");
            }
            if(p1.getOverdueSRM() != null) {
                p1.setStrO(new DecimalFormat("0.00").format(p1.getOverdueSRM()));
            } else{
                p1.setStrO("0.00");
            }
        }
        return lp;
    }

    /**
     * 无条件查询所有仪表盘信息
     * @return
     */
    @RequestMapping(value="/selectBill",produces = {"application/json;charset=utf-8"})
    public List<ReturnMoneyCount> findBill(ReturnMoneyCount returnMoneyCount){
        if(returnMoneyCount.getStrDate() != null && returnMoneyCount.getStrDate() != "" ){
            returnMoneyCount.setStrDateA(null);
            returnMoneyCount.setStrDateB(null);
        }
        List<ReturnMoneyCount> lp = dashboardInfoImpl.findBill(returnMoneyCount);
        for(int i = 0;i < lp.size();i++) {
            ReturnMoneyCount p1 = lp.get(i);
            if(p1.getDateSRM() != null){
                p1.setStrD(new DecimalFormat("0.00").format(p1.getDateSRM()));
            }else{
                p1.setStrD("0.00");
            }
            if(p1.getTodaySRM() != null) {
                p1.setStrT(new DecimalFormat("0.00").format(p1.getTodaySRM()));
            } else {
                p1.setStrT("0.00");
            }
            if(p1.getOverdueSRM() != null) {
                p1.setStrO(new DecimalFormat("0.00").format(p1.getOverdueSRM()));
            } else{
                p1.setStrO("0.00");
            }
        }
        return lp;
    }

    /**
     * 无条件查询所有仪表盘信息
     * @return
     */
    @RequestMapping(value="/selectOM",produces = {"application/json;charset=utf-8"})
    public List<OrderMoneyInfo> findOM(OrderMoneyInfo orderMoneyInfo){
        List<OrderMoneyInfo> lp0 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.clear();
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate0());
        List<OrderMoneyInfo> lp00 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp00);
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate1());
        List<OrderMoneyInfo> lp01 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp01);
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate2());
        List<OrderMoneyInfo> lp02 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp02);
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate3());
        List<OrderMoneyInfo> lp03 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp03);
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate4());
        List<OrderMoneyInfo> lp04 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp04);
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate5());
        List<OrderMoneyInfo> lp05 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp05);
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate6());
        List<OrderMoneyInfo> lp06 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp06);
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate7());
        List<OrderMoneyInfo> lp07 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp07);
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate8());
        List<OrderMoneyInfo> lp08 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp08);
        orderMoneyInfo.setStrDate(orderMoneyInfo.getDate9());
        List<OrderMoneyInfo> lp09 = dashboardInfoImpl.findOM(orderMoneyInfo);
        lp0.addAll(lp09);
        return lp0;
    }

}
